package com.hnust.service.impl;

import com.hnust.dao.AddAnnotationDao;
import com.hnust.domain.Anno;
import com.hnust.service.AddAnnotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class AddAnnotationServiceImpl implements AddAnnotationService {
    @Autowired
    private AddAnnotationDao addAnnotationDao;


    @Override
    public int addAnnotation(String stuId, String testId, String queId, String annoMsg) {
        String studentId= addAnnotationDao.queryStuIdByTestId(testId,stuId);
        System.out.println("studentId"+studentId);
//        如果对应的学号不存在
        if(studentId==null||studentId.isEmpty()) {
            return 0;
        }
//        如果题号找不到
        String questionId=addAnnotationDao.queryQueIdByTestId(testId,queId);
        System.out.println("questionId"+questionId);
        if(questionId==null||questionId.isEmpty()) {
            return 0;
        }
//        如果papId找不到
        String papId=addAnnotationDao.queryPapIdByTestId(testId);
        System.out.println("papId"+papId);
        if(papId==null||papId.isEmpty()) {
            return 0;
        }
        //        生成主键id
        String annoId= UUID.randomUUID().toString().replaceAll("-","");
        System.out.println("UUID="+annoId);
        Anno anno= new Anno(annoId,stuId,papId,queId,annoMsg);
        return addAnnotationDao.addAnnotation(anno);



    }
}
